/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package xowl.interpreter.frontends.owlxml;

/**
 *
 * @author Laurent WOUTERS
 */
public class OWLXMLLoader implements xowl.interpreter.frontends.Loader {
    static final String name = "OWL/XML Loader";
    
    @Override public xowl.lang.owl2.Ontology loadOntology(xowl.utils.logging.Logger logger, String docName, java.io.Reader reader, xowl.interpreter.frontends.OntologyListener listener) {
        xowl.lang.owl2.Ontology onto = null;
        org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser();
        try {
            parser.parse(new org.xml.sax.InputSource(reader));
            org.w3c.dom.Document document = parser.getDocument();
            for (int i=0; i!=document.getChildNodes().getLength(); i++) {
                 org.w3c.dom.Node node = document.getChildNodes().item(i);
                 if (node.getNodeName().equals(xowl.interpreter.frontends.VocOWL2.ontoOntology)) {
                     OntologyLoader loader = new OntologyLoader(listener);
                     onto = loader.load(node);
                     break;
                 }
            }
        }
        catch (java.lang.Exception ex) {
            logger.error(name, "Error while loading " + docName + ": " + ex.getMessage(), ex);
            return null;
        }
        return onto;
    }
    
    @Override public void loadQueries(xowl.utils.logging.Logger logger, String docName, java.io.Reader reader, xowl.interpreter.frontends.QueriesListener listener) {
        throw new java.lang.UnsupportedOperationException();
    }
}
